package com.budwk.app.sqfwV2.generator.dulaying;

import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CommonParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.ExcelRowDataParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BaseExcelGenerator;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.ResultOfExcelDataInto;
import com.budwk.app.sqfwV2.dto.dulaying.DuLaYingPropagandaOrScreeningPdfDTO;
import com.budwk.app.sqfwV2.dto.image.DuLaYingPropagandaOrScreeningExcelImageConfigBO;
import com.budwk.app.sqfwV2.enums.PropagandaOrScreeningEnum;
import com.budwk.app.util.ClassUtil;
import com.budwk.app.util.poiUtils.PictureUtils;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-06-15
 *
 * 都拉营街道宣传/排查记录 DuLaYingPropagandaOrScreening
 * 宣传排查台账.xlsx
 */
public class PropagandaAndScreeningExcelGenerator extends BaseExcelGenerator {

    /**
    * 自定义excel的表头数据
    *
    * @param excelParam         excel参数整体参数map
    * @param excelGenerateParam 创建excel所提供的参数
    */
    @Override
    protected void customerPopularHeaderData(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {

    }

    /**
    * 后端自定义维护表头数据
    *
    * @param excelParam         excel整体参数
    * @param excelGenerateParam 创建excel所提供的参数
    */
    @Override
    protected void customerPopularHeaderDataForAdmin(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {

    }

    /**
    * @param excelParam         excel整体参数
    * @param excelGenerateParam 创建excel所提供的参数
    * @return 判断excel是否含有数据
    */
    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeErgodic(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        // 如果不是数据检测，直接返回
        if (excelGenerateParam.getExcelConfig().getCreateExcelFileFlag()) return null;

        // 数据检测
        List<ExcelRowDataParam> dataList = excelGenerateParam.getDataList();
        ResultOfExcelDataInto resultOfExcelDataInto = new ResultOfExcelDataInto();
        resultOfExcelDataInto.setExcelHaveDataFlag(false);
        for (ExcelRowDataParam excelRowDataParam : dataList) {
            // 判断是否有满足条件的数据，只要检测到一条就可以结束
            if (addRowDataCondition(excelRowDataParam, excelGenerateParam)) {
                resultOfExcelDataInto.setExcelHaveDataFlag(true);
                break;
            }
        }
        return resultOfExcelDataInto;
    }

    /**
    * 根据行数据判断是否该条数据进入excel中
    *
    * @param rowDataParam       行数据
    * @param excelGenerateParam excel生成所提供的参数
    * @return 是/否
    */
    @Override
    protected boolean addRowDataCondition(ExcelRowDataParam rowDataParam, ExcelGenerateParam excelGenerateParam) {
        //DuLaYingPropagandaOrScreeningPdfDTO fieldDTO = (DuLaYingPropagandaOrScreeningPdfDTO) rowDataParam.getAbstractCustomerPdfCreateField();
        return true;
    }

    /**
    * 用户自定义填充excel实体数据
    *
    * @param listMap            数据数据
    * @param excelGenerateParam 创建excel所需的参数
    */
    @Override
    protected void customerPopularSheetData(List<Map<String, Object>> listMap, ExcelGenerateParam excelGenerateParam) {
        PictureUtils.concurrenceDownImg(listMap, this.getImageConfigBO());
    }

    /**
    * 自定义填充excel中每一行的数据
    *
    * @param rowDataMap   当前行的数据Map
    * @param rowDataParam 所提供的当前行的数据
    */
    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {
        //DuLaYingPropagandaOrScreeningPdfDTO fieldDTO = (DuLaYingPropagandaOrScreeningPdfDTO) rowDataParam.getAbstractCustomerPdfCreateField();
        
    }

    /**
     * 后端生成excel时候自定义填充excel中每一行的数据
     *
     * @param rowDataMap   当前行的数据Map
     * @param rowDataParam 所提供的当前行的数据
     */
    @Override
    protected void customerPopularRowDataMapForAdmin(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam) {
        //DuLaYingPropagandaOrScreeningPdfDTO fieldDTO = (DuLaYingPropagandaOrScreeningPdfDTO) rowDataParam.getAbstractCustomerPdfCreateField();
    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, ExcelRowDataParam rowDataParam, ExcelGenerateParam excelGenerateParam) {
        DuLaYingPropagandaOrScreeningPdfDTO fieldDTO = (DuLaYingPropagandaOrScreeningPdfDTO) rowDataParam.getAbstractCustomerPdfCreateField();

        Sqfw_formSummary_new formSummaryNew = (Sqfw_formSummary_new) rowDataParam.getCustomerParamMap().get("formSummaryNew");
        rowDataMap.put(ClassUtil.getField(CommonParam::getCommunity), formSummaryNew.getCommunity());
        rowDataMap.put(ClassUtil.getField(CommonParam::getCreateUserName), formSummaryNew.getCreateUserName());

        rowDataMap.put(ClassUtil.getField(DuLaYingPropagandaOrScreeningExcelImageConfigBO::getImages), PictureUtils.splitUrl(fieldDTO.getImages(), 1));
    }

    /**
    * 在创建之前判断excel中是否含有数据
    *
    * @param excelParam         创建之前excel中已经填充的数据
    * @param excelGenerateParam 所提供的excel创建的所需要的数据
    * @return 结果
    */
    @Override
    protected ResultOfExcelDataInto judgeExcelHaveDataBeforeCreate(Map<String, Object> excelParam, ExcelGenerateParam excelGenerateParam) {
        return null;
    }

    @Override
    protected String getTemplatePath(ExcelGenerateParam excelGenerateParam) {
        return "duLaYing/propagandaScreening.xlsx";
    }

    /**
    * 可以参照 {@link com.budwk.app.sqfw.enums.DownLoadFileNameEnum}
    *
    * @return 文件名名称
    */
    @Override
    public String getDownloadFileName(ExcelGenerateParam excelGenerateParam) {
        //TODO 在这里返回你生成的文件名名称
        // 注意注意注意不用带上后缀
        return PropagandaOrScreeningEnum.PROPAGANDA_SCREENING.getName();
    }


    @Override
    protected Class<?> getImageConfigBO() {
        return DuLaYingPropagandaOrScreeningExcelImageConfigBO.class;
    }

    /**
    * 允许用户在创建excel文件之前对配置进行修改
    *
    * @param excelFileCreateParamBO 创建excel的配置参数
    */
    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParamBO) {

    }
}
